package com.gyms.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gyms.R;
import com.gyms.activity.SeatChoseActivity;
import com.classic.okhttp.beans.HVVenueWeekTimesBean;
import com.gyms.base.BaseActivity;
import com.gyms.constant.Constants;

import java.util.List;

import utils.DateUtil;
import utils.ScreenUtils;
import utils.SizeUtils;

/**
 * ltx on 2016/11/11 09:26
 * 约定场馆的适配器
 */
public class OrderGymAdapter extends RecyclerView.Adapter<OrderGymAdapter.ViewHolder> implements View.OnClickListener {
    private LayoutInflater mInflater;
    /*private List<HVSceneBean> mHVSceneBeanList;*/
   private List<HVVenueWeekTimesBean>mHVVenueWeekTimesBeans;
    private String mVenueId,mProjectid;//场馆ID 项目ID
    private String mProjectName;//项目名称
    public OrderGymAdapter(Context context,String venueId,String mProjectid,String mProjectName)
    {
        mInflater = LayoutInflater.from(context);
        this.mContext=context;
        this.mVenueId=venueId;
        this.mProjectid=mProjectid;
        this.mProjectName=mProjectName;
    }
    private Context mContext;


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.order_gym_item,
                parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.mGymDay= (TextView) view.findViewById(R.id.tv_order_day);
        viewHolder.mGymTime= (TextView) view.findViewById(R.id.tv_order_time);
        viewHolder.mTvOrder= (TextView) view.findViewById(R.id.tv_order);
        viewHolder.mRlGymOrder= (RelativeLayout) view.findViewById(R.id.rl_order_gym);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        HVVenueWeekTimesBean mHVVenueWeekTimesBean=mHVVenueWeekTimesBeans.get(position);
       long date=mHVVenueWeekTimesBean.getVenueTime();

        long dateLL=date*1000;
        holder.mGymDay.setText(DateUtil.getWeek(dateLL));
        holder.mGymTime.setText(DateUtil.stampToDate(dateLL));
       if(mHVVenueWeekTimesBean.getIsBook()){//可预订
           holder.mGymDay.setTextColor(mContext.getResources().getColor(R.color.c_333333));
           holder.mGymTime.setTextColor(mContext.getResources().getColor(R.color.c_999999));
           holder.mTvOrder.setTextColor(mContext.getResources().getColor(R.color.c_0396EB));
           holder.mTvOrder.setBackgroundResource(R.drawable.sp_order_blue);
           holder.mTvOrder.setTag(position);
           holder.mTvOrder.setOnClickListener(this);

       }else{
           holder.mTvOrder.setBackgroundResource(R.drawable.sp_order_dddddd);
           holder.mGymDay.setTextColor(mContext.getResources().getColor(R.color.c_DDDDDD));
           holder.mGymTime.setTextColor(mContext.getResources().getColor(R.color.c_DDDDDD));
           holder.mTvOrder.setTextColor(mContext.getResources().getColor(R.color.c_DDDDDD));
       }
        if(position==mHVVenueWeekTimesBeans.size()-1){//最后的一项设置marginRight
            ScreenUtils.setMargins( holder.mRlGymOrder,SizeUtils.dp2px(mContext,12),0, SizeUtils.dp2px(mContext,15),0);
        }
    }

    @Override
    public int getItemCount() {
        return null==mHVVenueWeekTimesBeans?0:mHVVenueWeekTimesBeans.size();
    }



    @Override
    public void onClick(View v) {
        int pos= (int) v.getTag();
        switch (v.getId()){
            case R.id.tv_order:
                HVVenueWeekTimesBean mHVVenueWeekTimesBean=mHVVenueWeekTimesBeans.get(pos);
                Intent intent=new Intent(mContext,SeatChoseActivity.class);
                Bundle mBundle=new Bundle();
                mBundle.putSerializable(Constants.FLAG_INTENT_ORDER_GYN,mHVVenueWeekTimesBean);
                mBundle.putString(Constants.FLAG_INTENT_VENUEID,mVenueId);
                mBundle.putString(Constants.FLAG_INTENT_PROJECT_ID,mProjectid);
                mBundle.putInt(Constants.FLAG_INTENT_SELECT_POS,pos);
                mBundle.putString(Constants.FLAG_INTENT_PROJECTNAME_SEAT,mProjectName);
                intent.putExtras(mBundle);
                ((BaseActivity)mContext).startActivity(intent,false);
                break;
        }
    }

    public void setHVVenueWeekTimesBeans(List<HVVenueWeekTimesBean> HVVenueWeekTimesBeans) {
        mHVVenueWeekTimesBeans = HVVenueWeekTimesBeans;
    }

    public class ViewHolder extends RecyclerView.ViewHolder
    {
        public ViewHolder(View arg0)
        {
            super(arg0);
        }
        TextView mGymDay;
        TextView mGymTime;
        TextView mTvOrder;
        RelativeLayout mRlGymOrder;
    }

}
